<?php
class Producto extends AppModel
{
	var $name = 'Producto';
	var $belongsTo = 'Tipo';
	var $hasAndBelongsToMany = array('Menu','Pedido');
	var $displayField = 'nombre';
	var $actsAs = array ('Searchable');

	
	function indexData() 
	{
        $index = $this->data['Producto']['nombre'];
        return $index;
        }
	
	function reindexAll()
	{
		if(!$this->SearchIndex)
		{
			$this->SearchIndex=ClassRegistry::init('SearchIndex');
		}
		
		ini_set('max_execution_time',360);
		App::import('Model', $this->name);
		$newmodel = new $this->name();
		$data=$newmodel->findAll();
		foreach($data as $i=>$row)
		{
			$newmodel->data=$row;
			$index = $newmodel->indexData();
			if($index)
			{
				$searchEntry=$this->SearchIndex->find('first',array(
								'fields'=>array(
										'id'),
								'conditions'=>array(
										'model'=>$this->name,
										'association_key'=>$row[$this->name]['id'])));
				$index_data=array(
					'SearchIndex'=>array(
					'model'=>$this->name,
					'id'=>empty($searchEntry)? 0:
					$searchEntry['SearchIndex']['id'],'association_key'=>$row[$this->name]['id'],
					'data'=>$index));
					$res=$this->SearchIndex->save($index_data);
			}
		}
	}
}
?>